/*
 * @Description: Vite项目基本配置内容
 * @Version: 2.0
 * @Autor: 于新强
 * @Date: 2023-05-04 16:09:19
 * @LastEditors: 于新强
 * @LastEditTime: 2023-05-05 10:32:25
 */
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' // Vue3单文件语法支持
import legacy from '@vitejs/plugin-legacy' // 浏览器兼容
import Components from 'unplugin-vue-components/vite' // 组件自动引入
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers' //组件自动引入
import AutoImport from 'unplugin-auto-import/vite' // API 自动引入

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    legacy({
      targets: ['defaults', 'not IE 11'],
    }),
    Components({
      // 自定义组件所在文件夹，默认位置
      dirs: ['src/components'],
      resolvers: [AntDesignVueResolver()],
      extensions: ['vue'],//文件扩展
      // 配置type文件生成位置
      dts: 'src/components.d.ts'
    }),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/,],
      // 插件预设导入的API
      imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
      resolvers: [AntDesignVueResolver()],
      vueTemplate: true,
      cache: true,
      // 配置type文件生成位置
      dts: 'src/auto-imports.d.ts',
      eslintrc: {
        enabled: false, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
     })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host: '0.0.0.0',
    open: true,
    proxy: {}
  }
})
